package br.inf.solutions.apresentacoes.ssp.control;

import br.com.vexillum.control.GenericControl;
import br.com.vexillum.model.IActivatedEntity;
import br.com.vexillum.util.Return;

public class BaseController<E extends IActivatedEntity> extends GenericControl<E> {

	public BaseController(Class<E> classEntity) {
		super(classEntity);
	}

	@Override
	public Return listAll() {
		String sql = "FROM " + classEntity.getSimpleName() + " WHERE active = true ORDER BY name";
		if(data.get("entity") == null || (((IActivatedEntity) data.get("entity")).getActive() == null) || !((IActivatedEntity) data.get("entity")).getActive()){
			sql = sql.replace(" WHERE active = true", "");
		}
		data.put("sql", sql);
		return super.searchByHQL();
	}
	
}
